﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace OpenExpressApp.Module.WPF
{
    internal static class ViewAdapter
    {
        /// <summary>
        /// 把view的行为适配到control上。
        /// 同时也把control的行为适配到view上。
        /// </summary>
        /// <param name="view"></param>
        /// <param name="control"></param>
        public static void AdaptView(ObjectView view, TabItem control)
        {
            //IsActive
            control.IsSelected = view.IsActive;
            view.IsActiveChanged += (o, e) =>
            {
                control.IsSelected = view.IsActive;
            };

            //IsVisible
            control.Visibility = view.IsVisible ? Visibility.Visible : Visibility.Collapsed;
            //加了这句后，技术经济指标界面显示不出来……
            //原因是因为在QueryForm.xaml.cs中的这行代码：queryPane.Items.Remove(dcCondition);引起。
            //view.IsVisibleChanged += (o, e) =>
            //{
            //    control.SetValue(UIElement.VisibilityProperty, view.IsVisible ? Visibility.Visible : Visibility.Collapsed);
            //};
            control.IsVisibleChanged += (o, e) =>
            {
                //第二个叶签不能显示，暂时去除。
                //view.IsVisible = (bool)e.NewValue;
            };
        }
    }
}
